package com.douqu.game.main.msg;

import com.alibaba.fastjson.JSONObject;
import com.bean.core.util.HttpJsonUtils;
import com.douqu.game.core.config.*;
import com.douqu.game.core.config.challenge.WorldBossConfig;
import com.douqu.game.core.config.common.CommonData;
import com.douqu.game.core.config.common.GoodsData;
import com.douqu.game.core.config.sprite.MasterConfig;
import com.douqu.game.core.controller.PlayerController;
import com.douqu.game.core.database.model.PlayerModel;
import com.douqu.game.core.e.E_AdType;
import com.douqu.game.core.e.E_BattleDetailType;
import com.douqu.game.core.e.E_StableDataType;
import com.douqu.game.core.e.ReturnMessage;
import com.douqu.game.core.entity.Player;
import com.douqu.game.core.entity.activity.RankPlayer;
import com.douqu.game.core.entity.battle.BattleInitParam;
import com.douqu.game.core.entity.common.TwoTuple;
import com.douqu.game.core.entity.db.*;
import com.douqu.game.core.entity.ext.BagInfo;
import com.douqu.game.core.entity.ext.BoonInfo;
import com.douqu.game.core.entity.ext.SettingInfo;
import com.douqu.game.core.entity.ext.TaskInfo;
import com.douqu.game.core.entity.ext.data.boon.BonusData;
import com.douqu.game.core.entity.ext.data.boon.OnlineRewardData;
import com.douqu.game.core.entity.ext.data.boon.RechargeRecordData;
import com.douqu.game.core.entity.ext.data.card.CardData;
import com.douqu.game.core.entity.ext.data.challenge.ExpeditionData;
import com.douqu.game.core.entity.ext.data.challenge.InstanceData;
import com.douqu.game.core.entity.ext.data.challenge.WorldMapTaskBean;
import com.douqu.game.core.entity.ext.data.challenge.WorldMapTaskData;
import com.douqu.game.core.entity.ext.data.timeLimit.TimePropDB;
import com.douqu.game.core.entity.world.*;
import com.douqu.game.core.factory.*;
import com.douqu.game.core.protobuf.*;
import com.douqu.game.core.util.*;
import com.douqu.game.main.GameServer;
import com.douqu.game.main.server.ActivityCampManager;
import com.douqu.game.main.server.SpringContext;
import com.douqu.game.main.server.WorldManager;
import com.douqu.game.main.server.entity.RankPlayerDetail;
import com.douqu.game.main.service.PlayerService;
import com.douqu.game.main.util.MsgUtils;
import com.google.protobuf.InvalidProtocolBufferException;
import com.douqu.game.core.util.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

import static com.douqu.game.core.protobuf.SGCommonProto.E_ACTIVITY_HALL_TYPE.ACTIVITY_HALL_TYPE_MAIN;

/**
 * Created by bean on 2017/7/21.
 */
@Component
public class PlayerMsgChannel implements AMsgChannel {
    @Autowired
    private PlayerService playerService;

    @Override
    public void messageChannel(int code, PlayerController playerController, byte[] data) throws Exception {
        switch (code) {
            case SGMainProto.E_MSG_ID.MsgID_Player_GetInfo_VALUE:
                getPlayerInfo(playerController, code, data);
                break;
            case SGMainProto.E_MSG_ID.MsgID_Player_RequestBattle_VALUE:
                requestBattle(playerController, code, data);
                break;
            case SGMainProto.E_MSG_ID.MsgID_Player_SynBaseData_VALUE:
                playerBaseInfo(playerController);
                break;
            case SGMainProto.E_MSG_ID.MsgID_Player_EditPlayerName_VALUE:
                editPlayerName(playerController, data, code);
                break;
            case SGMainProto.E_MSG_ID.MsgID_Player_EditPlayerAvatar_VALUE:
                editPlayerAvatar(playerController, data, code);
                break;
            case SGMainProto.E_MSG_ID.MsgID_Player_ChangeConsumeRemindStatus_VALUE:
                changeConsumeRemindStatus(playerController, data, code);
                break;
            case SGMainProto.E_MSG_ID.MsgID_Player_ChangeEquippedSkill_VALUE:
                changeEquippedSkill(playerController, data, code);
                break;
            case SGMainProto.E_MSG_ID.MsgID_Player_SettingBoardInit_VALUE:
                settingBoardInit(playerController, data, code);
                break;
            case SGMainProto.E_MSG_ID.MsgID_Player_RedPointRemind_VALUE:
                redPoint(playerController, data, code);
                break;
            case SGMainProto.E_MSG_ID.MsgID_Player_GetInstanceRemainChallengeTime_VALUE:
                getAllInstanceRemainChallengeTime(playerController, data, code);
                break;
            case SGMainProto.E_MSG_ID.MsgID_Player_UpdateGuideProgress_VALUE:
                updateGuideProgress(playerController, data, code);
                break;
            case SGMainProto.E_MSG_ID.MsgID_Player_CdkUse_VALUE:
                cdkUse(playerController, data, code);
                break;
            case SGMainProto.E_MSG_ID.MsgID_Player_GetMobileCaptcha_VALUE:
                getMobileCaptcha(playerController, data, code);
                break;
            case SGMainProto.E_MSG_ID.MsgID_Player_BindingMobile_VALUE:
                bindingMobile(playerController, data, code);
                break;
            case SGMainProto.E_MSG_ID.MsgID_Player_FeedBack_VALUE:
                sendFeedBack(playerController, data, code);
                break;
            case SGMainProto.E_MSG_ID.MsgID_Player_RankList_VALUE:
                rankList(playerController, data, code);
                break;
            /******************************** 主将培养 *************************************/
            case SGMainProto.E_MSG_ID.MsgID_Player_MasterTrain_VALUE:
                masterTrain(playerController, data, code);
                break;
            case SGMainProto.E_MSG_ID.MsgID_Player_MasterTrainAccept_VALUE:
                masterTrainAccept(playerController, data, code);
                break;
            /******************************** 聊天消息 *************************************/
            case SGMainProto.E_MSG_ID.MSGID_Player_ChatMsg_VALUE:
                chatSend(playerController, data, code);
                break;
            case SGMainProto.E_MSG_ID.MSGID_Player_MainPageInfo_VALUE:
                mainPageInfo(playerController, data, code);
                break;
            case SGMainProto.E_MSG_ID.MSGID_Player_FunctionOpen_VALUE:
                functionOpen(playerController, data, code);
                break;
            case SGMainProto.E_MSG_ID.MSGID_Player_GetServerTime_VALUE:
                playerController.sendMsg(code, SGPlayerProto.S2C_GetServerTime.newBuilder()
                        .setCurrentServerTime(DataFactory.currentTime).build().toByteArray());
                break;
            case SGMainProto.E_MSG_ID.MsgID_Player_SetAutoRecover_VALUE:
                settingAutoRecover(playerController, data, code);
                break;
            case SGMainProto.E_MSG_ID.MSGID_Player_BuyFlashSale_VALUE:
                buyFlashSale(playerController, data, code);
                break;
            /************************活动大厅*******************************/
            case SGMainProto.E_MSG_ID.MSGID_Player_InitActivityHallDay_VALUE:
                initActivityHallDay(playerController,data,code);
                break;
            case SGMainProto.E_MSG_ID.MSGID_Player_InitActivityHallWeek_VALUE:
                initActivityHallWeek(playerController,code);
                break;
            //检测引导信息
            case SGMainProto.E_MSG_ID.MsgID_Player_CheckGuide_VALUE:
                checkGuide(playerController, code);
                break;
        }
    }

    /**
     * 检测引导信息
     * @param playerController
     * @param code
     */
    private void checkGuide(PlayerController playerController, int code) {
        SGPlayerProto.S2C_CheckGuide.Builder response = SGPlayerProto.S2C_CheckGuide.newBuilder();
        response.addAllTrueList(playerController.getPlayer().checkAllGuide());
        LogUtils.debug("返回给客户端引导信息：" + response.toString());
        playerController.sendMsg(code, response.build().toByteArray());
    }

    /**
     * 功能开启
     *
     * @param playerController
     * @param data
     * @param code
     */
    private void functionOpen(PlayerController playerController, byte[] data, int code) {
        SGPlayerProto.C2S_FunctionOpen request = null;
        try {
            request = SGPlayerProto.C2S_FunctionOpen.parseFrom(data);
        } catch (InvalidProtocolBufferException e) {
            e.printStackTrace();
            playerController.sendWarn(WordFactory.PARAM_ERROR);
            return;
        }

        int functionId = request.getFunctionId();
        LogUtils.debug("开启功能id:" + functionId);
        if (!CoreUtils.isFunctionUnLock(functionId, playerController.getPlayer())) {
            playerController.sendWarn(WordFactory.FUNCTION_NOT_OPEN, functionId);
            return;
        }

        SettingInfo settingInfo = playerController.getPlayer().getExtInfo(SettingInfo.class);
        settingInfo.addFunctionOpenId(functionId);
        LogUtils.debug("已开启功能id:" + settingInfo.getFunctionOpenIds());
        playerController.sendMsg(code, SGPlayerProto.S2C_FunctionOpen.newBuilder()
                .addAllFunctionId(settingInfo.getFunctionOpenIds()).build().toByteArray());

    }

    /**
     * 主页动态数据
     *
     * @param playerController
     * @param data
     * @param code
     */
    private void mainPageInfo(PlayerController playerController, byte[] data, int code) {
        SGPlayerProto.S2C_MainPageInfo.Builder response = SGPlayerProto.S2C_MainPageInfo.newBuilder();
        response.setBossIconShow(WorldInfoFactory.getInstance().getWorldBossData().isBossActive());
        SettingInfo settingInfo = playerController.getPlayer().getExtInfo(SettingInfo.class);
        response.addAllFunctionId(settingInfo.getFunctionOpenIds());
        response.setRechargeGuideShow(RechargeGuideUtils.isRechargeGuideShow(playerController.getPlayer()));

        Map<Integer, Integer> flashSaleMap = playerController.getPlayer().getBonusData().getInTimeFlashSaleRecord();
        for (Map.Entry<Integer, Integer> e : flashSaleMap.entrySet()) {
            response.addSaleList(
                    SGCommonProto.KeyListObject.newBuilder().setKey(e.getKey()).setValue(e.getValue()).build());
        }
        response.setTimeLimitActivityShow(
                TimeLimitedActivitiesConfig.isShowIcon(WorldInfoFactory.getInstance().getServerId(), playerController.getPlayer()));
        response.setHpInfo(SendUtils.getHpPercent(playerController));
        response.setPopInfo(packagePopInfo(playerController.getPlayer()));

        response.setAutoShowLogonBenefits(playerController.getPlayer().getBonusData().checkLoginBonus());
        //是否有累计在线奖励
        OnlineRewardData onlineRewardData = playerController.getPlayer().getOnlineData();
        response.setHaveOnlineReward(onlineRewardData.isGetAllReward());
        response.setOnlineCd((int) (onlineRewardData.getAllOnlineTime() / 1000));
       // WorldManager.timeTopRankCheck();
        //TODO 测试用 加天赋点
        if ( playerController.getPlayer().getTalentData().getTalentNote()==1)
        playerController.getPlayer().getTalentData().setTalentNote(100);
        //当前主线任务
        TaskInfo taskInfo = playerController.getPlayer().getExtInfo(TaskInfo.class);
        for (TaskDB taskDB:taskInfo.underwayMainTaskMap.values()){
            response.setCurrentMainTask(taskInfo.buildTaskDetail(taskDB));
            break;
        }
        //todo 测试
        //playerController.getPlayer().getSevenDayData().getRewardList();
        //playerController.getPlayer().getSevenDayData().getAllReward(31);
        //GameServer.getInstance().getWorldManager().timeTopRankCheck();
        //GameServer.getInstance().getWorldArenaData().setPlayerRank(playerController.getPlayer(),1);
        //playerController.getPlayer().checkAllGuide();
        //playerController.getPlayer().getInstanceData().getMaxInstance(1);
        LogUtils.debug("mainPageInfo------>>" + response);
        playerController.sendMsg(code, response.build().toByteArray());


    }

    private SGCommonProto.PopInfo packagePopInfo(Player player) {
        SGCommonProto.PopInfo.Builder builder = SGCommonProto.PopInfo.newBuilder();
        builder.setPubFree(player.getExtInfo(BoonInfo.class).getLotteryData().hasDiamondFree());   // 酒馆免费气泡
        builder.setPubLottery(player.getExtInfo(BoonInfo.class).getLotteryData().hasItemTenFree());    // 酒馆高级10连抽奖
        builder.setAltarFree(player.getExtInfo(BoonInfo.class).getAltarData().hasRedPointRemind()); // 祭坛免费
        builder.setTaskRewardCanReceive(player.getExtInfo(TaskInfo.class).checkMainTaskRedPoint());  // 主线任务奖励领取
        return builder.build();
    }

    /**
     * 获取玩家数据
     *
     * @param playerController
     * @param code
     * @param data
     */
    private void getPlayerInfo(PlayerController playerController, int code, byte[] data) {
        SGPlayerProto.C2S_GetInfo request = null;
        try {
            request = SGPlayerProto.C2S_GetInfo.parseFrom(data);
        } catch (InvalidProtocolBufferException e) {
            e.printStackTrace();
            playerController.sendWarn(WordFactory.PARAM_ERROR);
            return;
        }

        String playerIndex = request.getPlayerIndex();
        if (CoreUtils.isNullOrEmpty(playerIndex) || playerIndex.equals("-1")) {
            LogUtils.error("GM信息不是你想看就能看的->" + playerController.getName());
            playerController.sendUnknown();
            return;
        }
        TwoTuple<Player, PlayerController> playerResult = GameServer.getInstance().getWorldManager()
                .getPlayerResult(playerIndex);
        if (playerResult.getFirst() != null) {
            Player player = playerResult.getFirst();
            SGPlayerProto.S2C_GetInfo.Builder response = SGPlayerProto.S2C_GetInfo.newBuilder();
            SGCommonProto.PlayerBaseInfo.Builder baseInfo = SGCommonProto.PlayerBaseInfo.newBuilder();
            baseInfo.setPlayerIndex(player.getObjectIndex());
            baseInfo.setNickName(player.getName());
            baseInfo.setAvatar(player.avatar);
            baseInfo.setLv(player.getLv());
            baseInfo.setVipLv(player.getVipLevel());
            baseInfo.setExp(player.getExp());
            baseInfo.setFc(player.fc);
            baseInfo.setMasterId(player.master);
            baseInfo.setCamptypeValue(player.camp);
            baseInfo.setMobile(player.getMobile());
            int rTime = (int) (player.getCreateTime().getTime() / 1000);
            baseInfo.setRegistTime(rTime);
            SettingInfo settingInfo = player.getExtInfo(SettingInfo.class);
            int upLvTime = (int) (settingInfo.getLastLvUpTime() / 1000);
            baseInfo.setLastUpLvTime(upLvTime);
            response.setBaseInfo(baseInfo);

            List<SGCommonProto.CardGroup> cardGroupProto = getCardGroupProto(player, true);
            if (cardGroupProto.size() > 0) {
                response.setCardGroup(cardGroupProto.get(0));
            }

            response.addAllEquippedSkillIds(settingInfo.getEquipSkillIds());
            LogUtils.debug("玩家信息：" + baseInfo);
            playerController.sendMsg(code, response.build().toByteArray());

        } else {
            LogUtils.debug("玩家不存在：" + playerIndex);
            playerController.sendWarn(WordFactory.CROSS_SERVICE_QUERY);
            return;
        }
    }

    /**
     * 聊天消息发送
     *
     * @param playerController
     * @param data
     * @param code
     */
    private void chatSend(PlayerController playerController, byte[] data, int code) {
        VipConfig vipConfig = DataFactory.getInstance().getGameObject(DataFactory.VIP_KEY, playerController.getPlayer().getVipLevel());
        if(vipConfig == null || !vipConfig.chat){
            //不允许聊天
            playerController.sendWarn(WordFactory.VIP_LEVEL_NOT_ENOUGH);
            return;
        }
        SGPlayerProto.C2S_ChatMsg request = null;
        try {
            request = SGPlayerProto.C2S_ChatMsg.parseFrom(data);
        } catch (InvalidProtocolBufferException e) {
            e.printStackTrace();
            playerController.sendWarn(WordFactory.PARAM_ERROR);
            return;
        }

        LogUtils.debug("聊天参数：" + request);
        SGCommonProto.E_CHAT_TYPE chatType = request.getChatType();
        String content = request.getContent();
        if (CoreUtils.isNullOrEmpty(content)) {
            LogUtils.debug("聊天内容为空");
            playerController.sendWarn(WordFactory.CHAT_CONTENT_NOT_EMPTY);
            return;
        }

        if (chatType == SGCommonProto.E_CHAT_TYPE.CHAT_TYPE_CAMP
                || chatType == SGCommonProto.E_CHAT_TYPE.CHAT_TYPE_WORLD) {
            SGCommonProto.ChatItem.Builder chatItem = SGCommonProto.ChatItem.newBuilder();
            chatItem.setPlayerIndex(playerController.getPlayer().getObjectIndex());
            chatItem.setNickName(playerController.getPlayer().getName());
            chatItem.setCampValue(playerController.getPlayer().camp);
            chatItem.setAvatar(playerController.getPlayer().avatar);
            chatItem.setLv(playerController.getPlayer().getLv());
            chatItem.setVipLv(playerController.getPlayer().getVipLevel());
            chatItem.setChatType(chatType);
            chatItem.setContent(content);
            chatItem.setSendTime(DataFactory.currentTime);
            GameServer.getInstance().getWorldManager().dispatchChat(chatItem.build());
            // playerController.sendMsg(code,
            // SGPlayerProto.S2C_ChatMsg.newBuilder().build().toByteArray());

        } else {
            LogUtils.debug("暂无此类型聊天");
            playerController.sendWarn(WordFactory.NO_THIS_CHAT_TYPE);
            return;
        }
    }

    /**
     * 战斗请求
     *
     * @param playerController
     * @param code
     * @param data
     */
    private void requestBattle(PlayerController playerController, int code, byte[] data) {
        SGChallengeProto.C2S_RequestBattle request = null;
        try {
            request = SGChallengeProto.C2S_RequestBattle.parseFrom(data);
        } catch (InvalidProtocolBufferException e) {
            e.printStackTrace();
            playerController.sendWarn(WordFactory.PARAM_ERROR);
            return;
        }

        LogUtils.debug("战斗请求参数:" + request.toString());

        SGCommonProto.E_BATTLE_TYPE battleType = request.getBattleType();
        List<SGCommonProto.BattleParam> params = request.getBattleParamList();
        if (battleType == SGCommonProto.E_BATTLE_TYPE.BATTLE_TYPE_WORLD_BOSS) {
            WorldBossData worldBossData = WorldInfoFactory.getInstance().getWorldBossData();
            if (!worldBossData.isBossActive()) {
                LogUtils.debug("没有boss存活");
                playerController.sendWarn(WordFactory.ACTIVE_BOSS_UN_EXIST);
                return;
            }
            if (playerController.getPlayer().getBossData().getRemainChallengeTimes() <= 0) {
                LogUtils.debug(
                        "挑战次数已经用完,当前挑战次数剩余 :" + playerController.getPlayer().getBossData().getRemainChallengeTimes());
                playerController.sendWarn(WordFactory.BOSS_CHALLENGE_TIMES_NOT_ENOUGH);
                return;
            }
            //注释掉 发起战斗的时候记录玩家的挑战boss记录
            //worldBossData.addChallengeRecord(playerController.getObjectIndex(),
            //		worldBossData.getBossInfo().getIndexInfo(), 0);
            if (CoreUtils.isFunctionTestAccount(playerController.getPlayer().getAccount())) {
                ChallengeMsgChannel channel = SpringContext.getBean(ChallengeMsgChannel.class);
                channel.worldBossBattleEnd(playerController, worldBossData.getBossInfo().getIndexInfo(), null, false, new GoodsData[0], 0, "Test");
                playerController.sendWarn("测试账号直接通过");
            } else {
                WorldBossConfig worldBossConfig = DataFactory.getInstance().getGameObject(DataFactory.WORLD_BOSS_KEY,
                        Integer.parseInt(worldBossData.getBossInfo().getIndexInfo()));
                MsgUtils.startBattle(playerController, battleType, E_BattleDetailType.PVE_WORLD_BOSS,
                        worldBossData.getBossInfo().getIndexInfo(), new BattleInitParam(worldBossConfig.mapId));
            }
        } else if (battleType == SGCommonProto.E_BATTLE_TYPE.BATTLE_TYPE_INSTANCE) {
            int chapterId = 0;
            int levelId = 0;
            int supportCardId = 0;
            for (SGCommonProto.BattleParam param : params) {
                if ("chapterId".equals(param.getType())) {
                    chapterId = param.getValue();
                } else if ("levelId".equals(param.getType())) {
                    levelId = param.getValue();
                } else if ("supportCardId".equals(param.getType())) {
                    supportCardId = param.getValue();
                }
            }

            ChallengeMsgChannel channel = SpringContext.getBean(ChallengeMsgChannel.class);
            channel.requestLevelBattle(playerController, chapterId, levelId, supportCardId);
        } else if (battleType == SGCommonProto.E_BATTLE_TYPE.BATTLE_TYPE_WORLD_MAP) {

        } else {
            LogUtils.error("暂无此战斗类型");
            playerController.sendWarn(WordFactory.PARAM_ERROR);
            return;
        }
    }

    private void rankList(PlayerController playerController, byte[] data, int code)
            throws InvalidProtocolBufferException {
        SGPlayerProto.C2S_RankList request = SGPlayerProto.C2S_RankList.parseFrom(data);

        SGPlayerProto.S2C_RankList.Builder response = SGPlayerProto.S2C_RankList.newBuilder();
        if (request.getRankType() == SGCommonProto.E_RANK_TYPE.RANK_TYPE_UNKNOW) {
            LogUtils.error("排行榜请求参数错误,类型为0!");
            playerController.sendWarn(WordFactory.PARAM_ERROR);
            return;
        }

        response.setRankType(request.getRankType());

        SGCommonProto.RankInfo.Builder selfRank = SGCommonProto.RankInfo.newBuilder();
        selfRank.setName(playerController.getName());
        selfRank.setObjectIndex(playerController.getObjectIndex());
        selfRank.setCamp(SGCommonProto.E_CAMP_TYPE.forNumber(playerController.getPlayer().camp));
        selfRank.setAvatar(playerController.getPlayer().avatar);
        selfRank.setMaster(playerController.getPlayer().master);

        int rankIndex = 0;
        WorldManager worldManager = GameServer.getInstance().getWorldManager();
        if (SGCommonProto.E_RANK_TYPE.RANK_TYPE_ARENA == request.getRankType()) {
            WorldArenaData worldArenaData = GameServer.getInstance().getWorldArenaData();
            int selfRankValue = worldArenaData.getArenaRankByObjectIndex(playerController.getPlayer());
            selfRank.setRank(selfRankValue);
            selfRank.setValue(playerController.getPlayer().fc + "");

            List<WorldArenaBean> rankList = worldArenaData.getUnderTargetRankList(ConstantFactory.RANK_COUNT);

            List<String> ids = new ArrayList<>();
            Map<String, PlayerController> onlineMap = new ConcurrentHashMap<>();
            PlayerController player = null;
            for (WorldArenaBean rank : rankList) {
                player = worldManager.getPlayerController(rank.getObjectIndex());
                if (player != null)
                    onlineMap.put(rank.getObjectIndex(), player);
                else
                    ids.add(rank.getObjectIndex());
            }

            List<PlayerModel> playerListByIndex = playerService.getPlayerListByIndex(ids);
            SGCommonProto.RankInfo.Builder rankInfo = null;
            int index = -1;
            PlayerModel playerModel = null;
            for (WorldArenaBean rankBean : rankList) {
                rankInfo = SGCommonProto.RankInfo.newBuilder();
                rankInfo.setRank(++rankIndex);
                player = onlineMap.get(rankBean.getObjectIndex());
                if (player != null) {
                    rankInfo.setName(player.getName());
                    rankInfo.setObjectIndex(player.getObjectIndex());
                    rankInfo.setCamp(SGCommonProto.E_CAMP_TYPE.forNumber(player.getPlayer().camp));
                    rankInfo.setAvatar(player.getPlayer().avatar);
                    rankInfo.setValue(player.getPlayer().fc + "");
                    rankInfo.setMaster(player.getPlayer().master);
                } else {
                    index = playerListByIndex.indexOf(new PlayerModel(rankBean.getObjectIndex()));
                    if(index >= 0)
                    {
                        playerModel = playerListByIndex.get(index);
                        rankInfo.setName(playerModel.getName());
                        rankInfo.setObjectIndex(playerModel.getObjectIndex());
                        rankInfo.setCamp(SGCommonProto.E_CAMP_TYPE.forNumber(playerModel.getCamp()));
                        rankInfo.setAvatar(playerModel.getAvatar());
                        rankInfo.setValue(playerModel.getFc() + "");
                        rankInfo.setMaster(playerModel.getMaster());
                    }
                    else
                    {
                        LogUtils.error("RankList objectIndex is null or player not find -> " + rankBean);
                    }
                }
                response.addRankInfo(rankInfo);
            }
        } else {
            if (SGCommonProto.E_RANK_TYPE.RANK_TYPE_CAMP == request.getRankType()) {
                List<RankPlayer> rankPlayerList = ActivityCampManager.getInstance().getRankPlayerList();
                rankIndex = 0;
                SGCommonProto.RankInfo.Builder rankInfo = null;
                for (RankPlayer rankPlayer : rankPlayerList) {
                    rankInfo = SGCommonProto.RankInfo.newBuilder();
                    rankInfo.setRank(++rankIndex);
                    rankInfo.setObjectIndex(rankPlayer.getObjectIndex());
                    rankInfo.setName(rankPlayer.getName());
                    rankInfo.setCamp(SGCommonProto.E_CAMP_TYPE.forNumber(rankPlayer.getCamp()));
                    rankInfo.setAvatar(rankPlayer.getAvatar());
                    rankInfo.setMaster(rankPlayer.getMaster());
                    rankInfo.setValue(rankPlayer.getValue() + "");
                    response.addRankInfo(rankInfo);

                    if (rankPlayer.getObjectIndex().equals(playerController.getObjectIndex())) {
                        selfRank.setRank(rankInfo.getRank());
                        selfRank.setValue(rankInfo.getValue());
                    }
                }

                if (selfRank.getRank() == 0) {
                    int myRank = ActivityCampManager.getInstance().getMyRank(playerController.getObjectIndex());
                    myRank = myRank < 0 ? 0 : myRank;
                    selfRank.setRank(myRank);
                    selfRank.setValue(playerController.getPlayer().getCampBattleData().curTotalExploit + "");
                }
            } else {
                List<WorldRankBean> rankBeanList = GameServer.getInstance().getWorldManager()
                        .getRankList(request.getRankType());
                if (rankBeanList == null) {
                    LogUtils.error("请求排行榜参数错误 -> " + request.getRankType());
                    playerController.sendWarn(WordFactory.PARAM_ERROR);
                    return;
                }

                rankIndex = 0;
                RankPlayerDetail rankPlayerDetail = null;
                int lastRankValue = 0;
                SGCommonProto.RankInfo.Builder rankInfo = null;
                for (WorldRankBean rankBean : rankBeanList) {
                    rankInfo = SGCommonProto.RankInfo.newBuilder();
                    rankInfo.setRank(++rankIndex);
                    rankInfo.setObjectIndex(rankBean.getObjectIndex());
                    rankInfo.setValue(rankBean.getValue() + "");

                    rankPlayerDetail = worldManager.getRankPlayer(rankBean.getObjectIndex());
                    if (rankPlayerDetail == null) {
                        LogUtils.error("玩家已被删除,请检查 -> " + rankBean.getObjectIndex());
                    } else {
                        rankInfo.setName(rankPlayerDetail.getName());
                        rankInfo.setCamp(SGCommonProto.E_CAMP_TYPE.forNumber(rankPlayerDetail.getCamp()));
                        rankInfo.setAvatar(rankPlayerDetail.getAvatar());
                        rankInfo.setMaster(rankPlayerDetail.getMaster());
                        response.addRankInfo(rankInfo);
                    }

                    if (rankBean.getObjectIndex().equals(playerController.getObjectIndex())) {
                        selfRank.setRank(rankInfo.getRank());
                        selfRank.setValue(rankInfo.getValue());
                    }

                    lastRankValue = (int) rankBean.getValue();
                }

                if (selfRank.getRank() == 0 && rankBeanList.size() > 0) {
                    int myRank = 0;
                    if (SGCommonProto.E_RANK_TYPE.RANK_TYPE_FC == request.getRankType()) {
                        myRank = playerService.getMyFCRank(playerController.getPlayer().fc) + 1;
                        myRank = myRank <= ConstantFactory.RANK_COUNT ? ConstantFactory.RANK_COUNT + 1 : myRank;
                        selfRank.setValue(playerController.getPlayer().fc + "");
                    } else if (SGCommonProto.E_RANK_TYPE.RANK_TYPE_MONEY == request.getRankType()) {
                        if (playerController.getPlayer().getVipExp() != 0) {
                            myRank = rankBeanList.size() + (lastRankValue - playerController.getPlayer().getVipExp());
                            selfRank.setValue(playerController.getPlayer().getVipExp() + "");
                        }
                    } else if (SGCommonProto.E_RANK_TYPE.RANK_TYPE_INSTANCE == request.getRankType()) {

                        InstanceData instanceData = playerController.getPlayer().getInstanceData();
                        myRank = rankBeanList.size() + (lastRankValue - instanceData.getTotalStart());
                        selfRank.setValue(instanceData.getTotalStart() + "");

                    } else if (SGCommonProto.E_RANK_TYPE.RANK_TYPE_EXPEDITION == request.getRankType()) {
                        ExpeditionData expeditionData = playerController.getPlayer().getExpeditionData();
                        if (expeditionData.getCurrentLevelNum() != 0) {
                            myRank = rankBeanList.size() + (lastRankValue - expeditionData.getCurrentLevelNum());
                            selfRank.setValue(expeditionData.getCurrentLevelNum() + "");
                        }
                    } else if (SGCommonProto.E_RANK_TYPE.RANK_TYPE_WORLDMAP == request.getRankType()) {
                        WorldMapTaskData mapTaskInfo = playerController.getPlayer().getWorldMapTaskData();
                        if (mapTaskInfo.getMilitaryExploitValue() > 0) {
                            // 有排行
                            myRank = rankBeanList.size() + (lastRankValue - mapTaskInfo.getMilitaryExploitValue());
                            selfRank.setValue(mapTaskInfo.getMilitaryExploitValue() + "");
                        }
                    }
                    myRank = myRank < 0 ? 0 : myRank;
                    selfRank.setRank(myRank);
                }
            }

        }

        response.setSelfRank(selfRank);

        playerController.sendMsg(code, response.build().toByteArray());
    }

    /**
     * cdk的使用
     *
     * @param playerController
     * @param data
     * @param code
     */
    private void cdkUse(PlayerController playerController, byte[] data, int code)
            throws InvalidProtocolBufferException {
        SGPlayerProto.C2S_CdkUse request = SGPlayerProto.C2S_CdkUse.parseFrom(data);

        String cdk = request.getCdkCode();

        // ActivityMsgChannel.test(cdk, playerController);
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("serverRuleId", playerController.getServerRuleId());
        jsonObject.put("objectIndex", playerController.getObjectIndex());
        jsonObject.put("nickName", playerController.getPlayer().getName());
        jsonObject.put("serverId", GameServer.getInstance().getServerId());
        jsonObject.put("cdk", cdk);
        // 新增两个验证参数 创建时间与等级
        jsonObject.put("createRoleTime", playerController.getPlayer().getCreateTime().getTime());
        jsonObject.put("level", playerController.getPlayer().getLv());
        JSONObject result = HttpJsonUtils.httpPost(GameServer.getInstance().getAuthServerHost() + HttpFactory.SERVER_USE_CDK_CODE, jsonObject);

        if (result == null) {
            LogUtils.error("请求认证服务器使用cdk码出错");
            playerController.sendWarn(WordFactory.SERVER_DATA_ERROR);
            return;
        }
        LogUtils.info("请求认证服务器使用cdk码：" + result.toString());
        String resultCode = result.getString("code");
        if (ReturnMessage.SUCCESS.getCode().equals(resultCode)) {// 成功
            String reward = result.getString("data");
            GoodsData[] goods = LoadUtils.loadGoodDataToArray("cdk", reward);
            for (GoodsData goodsData : goods) {
                if (!goodsData.check(PlayerMsgChannel.class, "cdk", 1)) {
                    LogUtils.warn("物品不存在：" + reward);
                    playerController.sendWarn(WordFactory.PARAM_ERROR);
                    return;
                }
            }
            playerController.getPlayer().getExtInfo(BagInfo.class).addGoods(goods, null);
            playerController.sendMsg(code, SGPlayerProto.S2C_CdkUse.newBuilder().setCdkCode(cdk).build().toByteArray());
        } else if (ReturnMessage.CDK_NOT_FIND_OR_EXPIRED.getCode().equals(resultCode)) {
            LogUtils.warn(ReturnMessage.CDK_NOT_FIND_OR_EXPIRED.getMsg() + ":" + cdk);
            playerController.sendWarn(WordFactory.CDK_NOT_FIND_OR_EXPIRED);
            return;
        } else if (ReturnMessage.CDK_USE_MAX_COUNT.getCode().equals(resultCode)) {
            LogUtils.warn(ReturnMessage.CDK_USE_MAX_COUNT.getMsg() + ":" + cdk);
            playerController.sendWarn(WordFactory.CDK_USE_MAX_COUNT);
            return;
        } else if (ReturnMessage.CDK_ALREADY_USE.getCode().equals(resultCode)) {
            LogUtils.warn(ReturnMessage.CDK_ALREADY_USE.getMsg() + ":" + cdk);
            playerController.sendWarn(WordFactory.CDK_ALREADY_USE);
            return;
        } else if (ReturnMessage.CDK_NOT_OPEN.getCode().equals(resultCode)) {
            LogUtils.warn(ReturnMessage.CDK_NOT_OPEN.getMsg() + ":" + cdk);
            playerController.sendWarn(WordFactory.CDK_NOT_OPEN);
            return;
        } else if (ReturnMessage.CDK_SERVER_NOT_CONFORM.getCode().equals(resultCode)) {
            LogUtils.warn(ReturnMessage.CDK_SERVER_NOT_CONFORM.getMsg() + ":" + cdk);
            playerController.sendWarn(WordFactory.CDK_SERVER_NOT_CONFORM);
            return;
        } else if (ReturnMessage.CDK_ROLE_CREATETIME_LATE.getCode().equals(resultCode)) {
            LogUtils.warn(ReturnMessage.CDK_ROLE_CREATETIME_LATE.getMsg() + ":" + cdk);
            playerController.sendWarn(WordFactory.CDK_ROLE_CREATETIME_LATE);
            return;
        } else if (ReturnMessage.CDK_ROLE_LEVEL_LOW.getCode().equals(resultCode)) {
            LogUtils.warn(ReturnMessage.CDK_ROLE_LEVEL_LOW.getMsg() + ":" + cdk);
            playerController.sendWarn(WordFactory.CDK_ROLE_LEVEL_LOW);
            return;
        } else if (ReturnMessage.CDK_PLATFORM_ERROR.getCode().equals(resultCode)) {
            LogUtils.warn(ReturnMessage.CDK_PLATFORM_ERROR.getMsg() + ":" + cdk);
            playerController.sendWarn(WordFactory.CDK_PLATFORM_ERROR);
            return;
        } else {
            LogUtils.warn(ReturnMessage.PARAM_ERROR.getMsg() + ":" + cdk);
            playerController.sendWarn(WordFactory.PARAM_ERROR);
            return;
        }
    }

    /**
     * 更新引导进度
     *
     * @param playerController
     * @param data
     * @param code
     */
    private void updateGuideProgress(PlayerController playerController, byte[] data, int code) {
        SGPlayerProto.C2S_UpdateGuideProgress request = null;
        try {
            request = SGPlayerProto.C2S_UpdateGuideProgress.parseFrom(data);
        } catch (InvalidProtocolBufferException e) {
            e.printStackTrace();
            playerController.sendWarn(WordFactory.PARAM_ERROR);
            return;
        }

        SettingInfo extInfo = playerController.getPlayer().getExtInfo(SettingInfo.class);
        extInfo.setGuideProgress(request.getGuideProgress());
        playerController.sendMsg(code, SGPlayerProto.S2C_UpdateGuideProgress.newBuilder()
                .setGuideProgress(request.getGuideProgress()).build().toByteArray());

    }

    /***
     * 获取验证码
     *
     * @param playerController
     * @param data
     * @param code
     */
    public void getMobileCaptcha(PlayerController playerController, byte[] data, int code) {
        SGPlayerProto.C2S_GetMobileCaptcha b = null;
        try {
            b = SGPlayerProto.C2S_GetMobileCaptcha.parseFrom(data);
        } catch (InvalidProtocolBufferException e) {
            e.printStackTrace();
        }
        if (b == null) {
            playerController.sendWarn(WordFactory.PARAM_ERROR);
            return;
        }
        String mobile = b.getMobile();
        if (!CoreUtils.checkPhoneFormat(mobile)) {
            playerController.sendWarn(WordFactory.PARAM_ERROR, WordFactory.INVALID_PHONE_NUMBER);
        }
        //发送到认证服去请求短信验证
        JSONObject json = HttpJsonUtils.httpPost(GameServer.getInstance().getAuthServerHost() + HttpFactory.PLAYER_GET_CAPTCHA + "?phone=" + mobile);
        if(json == null)
        {
            LogUtils.error("result is null");
            playerController.sendWarn(WordFactory.PARAM_ERROR);
            return;
        }

        String result = json.getString("data");
        if (StringUtils.isNullOrEmpty(result))
        {
            LogUtils.error("result is null");
            playerController.sendWarn(WordFactory.PARAM_ERROR);
            return;
        }

        playerController.sendMsg(code, SGPlayerProto.S2C_GetMobileCaptcha.newBuilder().setCode(result).setMobile(mobile)
                .build().toByteArray());
    }

    /***
     * 绑定手机号
     *
     * @param playerController
     * @param data
     * @param code
     */
    public void bindingMobile(PlayerController playerController, byte[] data, int code) {
        SGPlayerProto.C2S_BindingMobile b = null;
        try {
            b = SGPlayerProto.C2S_BindingMobile.parseFrom(data);
        } catch (InvalidProtocolBufferException e) {
            e.printStackTrace();
        }
        if (b == null) {
            playerController.sendWarn(WordFactory.PARAM_ERROR);
            return;
        }
        String mobile = b.getMobile();
        if (!CoreUtils.checkPhoneFormat(mobile)) {
            playerController.sendWarn(WordFactory.PARAM_ERROR, WordFactory.INVALID_PHONE_NUMBER);
        }
        PlayerService playerService = SpringContext.getBean(PlayerService.class);
        playerService.updateMobile(mobile, playerController.getPlayer().getUid());
        playerController.getPlayer().setMobile(mobile);
        playerController.sendMsg(code,
                SGPlayerProto.S2C_BindingMobile.newBuilder().setMobile(mobile).build().toByteArray());

    }

    public void sendFeedBack(PlayerController playerController, byte[] data, int code) {
        SGPlayerProto.C2S_FeedBack b = null;
        try {
            b = SGPlayerProto.C2S_FeedBack.parseFrom(data);
        } catch (InvalidProtocolBufferException e) {
            e.printStackTrace();
        }
        if (b == null) {
            playerController.sendWarn(WordFactory.PARAM_ERROR);
            return;
        }
        String content = b.getContent();
        if (com.alibaba.druid.util.StringUtils.isEmpty(content)) {
            playerController.sendWarn(WordFactory.PARAM_ERROR);
            return;
        }
        PlayerService playerService = SpringContext.getBean(PlayerService.class);
        playerService.feedBack(playerController.getObjectIndex(), content);
        playerController.sendMsg(code,
                SGPlayerProto.S2C_FeedBack.newBuilder().setContent(content).build().toByteArray());
    }

    /**
     * 获取各个副本挑战剩余次数
     *
     * @param playerController
     * @param data
     * @param code
     */
    private void getAllInstanceRemainChallengeTime(PlayerController playerController, byte[] data, int code) {
        SGPlayerProto.S2C_GetInstanceRemainChallengeTime.Builder response = SGPlayerProto.S2C_GetInstanceRemainChallengeTime
                .newBuilder();
        response.setHeroTempleRemainChallengeTime(
                playerController.getPlayer().getHeroTempleData().getTodayRemainChallengeTimes());
        response.setOfficialRankRemainChallengeTime(
                playerController.getPlayer().getOfficialData().getTodayRemainChallengeTimes());
        response.setArenaRemainChallengeTime(
                playerController.getPlayer().getArenaData().getRemainTodayChallengeTimes());
        response.setExpeditionRemainChallengeTime(
                playerController.getPlayer().getExpeditionData().getRemainChallengeTime());
        LogUtils.debug("获取各个副本挑战剩余次数:" + response.toString());
        playerController.sendMsg(code, response.build().toByteArray());
    }

    private void redPoint(PlayerController playerController, byte[] data, int code) {
        SGPlayerProto.S2C_RedPointRemind.Builder response = SGPlayerProto.S2C_RedPointRemind.newBuilder();
        List<SGCommonProto.E_RED_POINT_TYPE> allRedPointTypes = playerController.getPlayer()
                .getAllRedPointTypes(DataFactory.currentTime);
        LogUtils.debug("主动请求目前存在的红点提示:\n" + allRedPointTypes.toString());
        response.addAllTypes(allRedPointTypes);
        response.setIsRequest(true);
        playerController.sendMsg(code, response.build().toByteArray());
    }

    /**
     * 初始化设置面板
     *
     * @param playerController
     * @param data
     * @param code
     */
    private void settingBoardInit(PlayerController playerController, byte[] data, int code) {

        WorldOfficialBean rankBean = WorldInfoFactory.getInstance().getWorldOfficialData()
                .getRankInfoByObjectIndex(playerController.getPlayer());

        SGPlayerProto.S2C_SettingBoardInit.Builder response = SGPlayerProto.S2C_SettingBoardInit.newBuilder();
        SettingInfo settingInfo = playerController.getPlayer().getExtInfo(SettingInfo.class);
        response.setOfficialRankId(rankBean == null ? 15 : rankBean.getRankId());
        response.setChangeNameTimes(settingInfo.getPlayerNameChangeTimes());
        response.setNewUnlockSkillId(settingInfo.getNewUnlockSkillId());
        settingInfo.removeNewUnlockSkill();
        // 返回给客户端
        playerController.sendMsg(code, response.build().toByteArray());
    }

    /**
     * 改变上阵技能
     *
     * @param playerController
     * @param data
     * @param code
     */
    private void changeEquippedSkill(PlayerController playerController, byte[] data, int code) {
        SGPlayerProto.C2S_ChangeEquippedSkill request = null;
        try {
            request = SGPlayerProto.C2S_ChangeEquippedSkill.parseFrom(data);
        } catch (InvalidProtocolBufferException e) {
            e.printStackTrace();
        }
        if (request == null) {
            playerController.sendWarn(WordFactory.PARAM_ERROR);
            return;
        }

        List<Integer> ids = request.getEquipSkillList();
        LogUtils.debug("changeEquippedSkill 请求参数->ids:" + ids);
        if (ids.size() == 0) {
            playerController.sendWarn(WordFactory.PARAM_ERROR);
            return;
        }
        MasterConfig masterConfig = DataFactory.getInstance().getGameObject(DataFactory.MASTER_KEY,
                playerController.getPlayer().master);
        if (masterConfig == null) {
            LogUtils.debug("主将不存在->masterId:" + playerController.getPlayer().master);
            playerController.sendWarn(WordFactory.SERVER_DATA_ERROR);
            return;
        }
        List<Integer> lockSkillIds = new ArrayList<>();
        for (CommonData commonData : masterConfig.skills) {
            if (playerController.getPlayer().getLv() >= commonData.id) {
                lockSkillIds.add(commonData.value);
            }
        }
        for (Integer id : ids) {
            if (DataFactory.getInstance().getGameObject(DataFactory.SKILL_KEY, id) == null) {
                LogUtils.debug("技能不存在：" + id);
                playerController.sendWarn(WordFactory.PARAM_ERROR);
                return;
            }
            if (!lockSkillIds.contains(id)) {
                playerController.sendWarn(WordFactory.SKILL_UNLOCK);
                return;
            }
        }

        SettingInfo settingInfo = playerController.getPlayer().getExtInfo(SettingInfo.class);
        LogUtils.debug("已上阵的技能：" + settingInfo.getEquipSkillIds());
        settingInfo.changeEquipSkill(ids);
        LogUtils.debug("已上阵的技能：" + settingInfo.getEquipSkillIds());
        // 返回给客户端
        playerController.sendMsg(code,
                SGPlayerProto.S2C_ChangeEquippedSkill.newBuilder().addAllEquipSkill(ids).build().toByteArray());

    }

    /**
     * 改变消费提醒状态
     *
     * @param playerController
     * @param data
     * @param code
     */
    private void changeConsumeRemindStatus(PlayerController playerController, byte[] data, int code) {
        SGPlayerProto.C2S_ChangeConsumeRemindStatus request = null;
        try {
            request = SGPlayerProto.C2S_ChangeConsumeRemindStatus.parseFrom(data);
        } catch (InvalidProtocolBufferException e) {
            e.printStackTrace();
        }
        if (request == null) {
            playerController.sendWarn(WordFactory.PARAM_ERROR);
            return;
        }

        int key = request.getKey();
        boolean isShowRemind = request.getIsShowRemind();
        SettingInfo settingInfo = playerController.getPlayer().getExtInfo(SettingInfo.class);
        LogUtils.debug("改变消费提醒前的数据: " + settingInfo.getConsumeNotRemindList());
        if (isShowRemind) {
            settingInfo.getConsumeNotRemindList().remove(Integer.valueOf(key));
        } else {
            if (!settingInfo.getConsumeNotRemindList().contains(Integer.valueOf(key))) {
                settingInfo.getConsumeNotRemindList().add(key);
            }
        }
        LogUtils.debug("改变消费提醒请求参数 key: " + key + ", isShowRemind:" + isShowRemind);
        // 改变消费提醒后的数据
        LogUtils.debug("改变消费提醒后的数据: " + settingInfo.getConsumeNotRemindList());
        // 返回给客户端
        playerController.sendMsg(code, SGPlayerProto.S2C_ChangeConsumeRemindStatus.newBuilder().setKey(key)
                .setIsShowRemind(isShowRemind).build().toByteArray());

    }

    /**
     * 修改名称
     *
     * @param playerController
     * @param data
     * @param code
     */
    private void editPlayerName(PlayerController playerController, byte[] data, int code) {
        SGPlayerProto.C2S_EditPlayerName request = null;
        try {
            request = SGPlayerProto.C2S_EditPlayerName.parseFrom(data);
        } catch (InvalidProtocolBufferException e) {
            e.printStackTrace();
        }
        if (request == null) {
            playerController.sendWarn(WordFactory.PARAM_ERROR);
            return;
        }
        String name = request.getPlayerName();
        LogUtils.debug("修改的名字请求参数:" + name);
        if (StringUtils.isNullOrEmpty(name)) {
            playerController.sendWarn(WordFactory.NAME_NOT_EMPTY);
            return;
        }
        name = name.replaceAll(" ", "");
        if (name.length() == 0) {
            playerController.sendWarn(WordFactory.NAME_NOT_EMPTY);
            return;
        }
        if (name.length() > ConstantFactory.NAME_MAX_LENGTH) {
            LogUtils.debug("修改的名字过长:" + name);
            playerController.sendWarn(WordFactory.NAME_TOO_LONG);
            return;
        }
        SettingInfo settingInfo = playerController.getPlayer().getExtInfo(SettingInfo.class);
        BagInfo bagInfo = playerController.getPlayer().getExtInfo(BagInfo.class);
        StableDataConfig stableDataConfig = DataFactory.getInstance().getGameObject(DataFactory.STABLE_DATA_KEY,
                E_StableDataType.UPDATE_NAME_CONSUME.getCode());
        if (!settingInfo.isFirstChangeName()) {
            // 判断钻石是否够
            if (stableDataConfig == null || stableDataConfig.goods.length == 0) {
                playerController.sendWarn(WordFactory.PARAM_ERROR);
                return;
            }

            if (stableDataConfig.goods[0].type != 0 && stableDataConfig.goods[0].id != 0
                    && stableDataConfig.goods[0].value != 0) {

                int count = bagInfo.getGoodsCount(stableDataConfig.goods[0].type, stableDataConfig.goods[0].id);
                // 获取需要的资源
                if (count < stableDataConfig.goods[0].value) {
                    LogUtils.debug("钻石不足，拥有：" + playerController.getPlayer().money + "， 需要：" + 10);
                    playerController.sendWarn(WordFactory.ASSET_NOT_ENOUGH, 1);
                    return;
                }
            }
        }

        JSONObject jsonObject = getJsonObject(playerController, name, null);

        JSONObject result = HttpJsonUtils.httpPost(GameServer.getInstance().getAuthServerHost() + HttpFactory.PLAYER_UPDATE_RECORD,
                jsonObject);
        if (result == null) {
            LogUtils.error("请求认证服务器验证名称合法性出错：");
            playerController.sendWarn(WordFactory.PARAM_ERROR);
            return;
        }
        LogUtils.debug("请求认证服务器名字是否重复参数：" + result.toString());
        String resultCode = result.getString("code");
        if (Integer.parseInt(resultCode) == 0) {// 成功
            // 扣除资源
            if (!settingInfo.isFirstChangeName()) {
                bagInfo.addGoods(new GoodsData(stableDataConfig.goods[0].type, stableDataConfig.goods[0].id,
                        -stableDataConfig.goods[0].value));
                // playerController.getPlayer().addMoney(-10);
            }
            LogUtils.debug("修改的名字合法,返回成功");
            settingInfo.addPlayerNameChangeTimes();
            String beforeName = playerController.getName();
            playerController.getPlayer().setName(name);

            GameServer.getInstance().getWorldManager().updateRankPlayerDetail(playerController.getPlayer());
            // 返回给客户端
            playerController.sendMsg(code,
                    SGPlayerProto.S2C_EditPlayerName.newBuilder().setPlayerName(name).build().toByteArray());
        } else if (resultCode.equals(ReturnMessage.NICKNAME_EXITS.getCode())) {
            playerController.sendWarn(WordFactory.NAME_EXIST);
            return;
        } else {
            playerController.sendWarn(WordFactory.SERVER_DATA_ERROR);
            return;
        }
    }

    /**
     * 修改头像
     *
     * @param playerController
     * @param data
     * @param code
     */
    private void editPlayerAvatar(PlayerController playerController, byte[] data, int code) {
        SGPlayerProto.C2S_EditPlayerAvatar request = null;
        try {
            request = SGPlayerProto.C2S_EditPlayerAvatar.parseFrom(data);
        } catch (InvalidProtocolBufferException e) {
            e.printStackTrace();
        }
        if (request == null) {
            playerController.sendWarn(WordFactory.PARAM_ERROR);
            return;
        }

        String avatar = request.getPlayerAvatar();
        LogUtils.debug("修改的头像请求参数:" + avatar);
        if (StringUtils.isNullOrEmpty(avatar)) {
            playerController.sendWarn(WordFactory.PARAM_ERROR);
            return;
        }

        JSONObject jsonObject = getJsonObject(playerController, null, avatar);
        if (jsonObject == null) {
            playerController.sendWarn(WordFactory.PARAM_ERROR);
            return;
        }
        LogUtils.debug("请求认证服务器修改头像参数：" + jsonObject.toString());
        JSONObject result = HttpJsonUtils
                .httpPost(GameServer.getInstance().getAuthServerHost() + HttpFactory.PLAYER_UPDATE_RECORD2, jsonObject);
        if (result == null) {
            playerController.sendWarn(WordFactory.PARAM_ERROR);
            LogUtils.error("返回出错");
            return;
        }
        LogUtils.debug("请求认证服务器修改头像返回：" + result.toString());
        String resultCode = result.getString("code");
        if (Integer.parseInt(resultCode) == 0) {// 成功
            playerController.getPlayer().avatar = avatar;

            GameServer.getInstance().getWorldManager().updateRankPlayerDetail(playerController.getPlayer());
            // 返回给客户端
            playerController.sendMsg(code,
                    SGPlayerProto.S2C_EditPlayerAvatar.newBuilder().setPlayerAvatar(avatar).build().toByteArray());
        } else {
            playerController.sendWarn(WordFactory.SERVER_DATA_ERROR);
            return;
        }
    }

    /**
     * 获取修改认证服务器参数的json对象
     *
     * @param playerController
     * @param name
     * @param avatar
     * @return
     */
    private JSONObject getJsonObject(PlayerController playerController, String name, String avatar) {
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("channel", playerController.getPlayer().channel);
        jsonObject.put("account", playerController.getPlayer().getAccount());

        jsonObject.put("playerName", name);
        jsonObject.put("avatar", avatar);
        jsonObject.put("serverId", GameServer.getInstance().getServerId());
        return jsonObject;
    }

    public void playerBaseInfo(PlayerController playerController) {
        SGPlayerProto.S2C_SynBaseData.Builder response = SGPlayerProto.S2C_SynBaseData.newBuilder();

        SGCommonProto.BaseData.Builder data = SGCommonProto.BaseData.newBuilder();

        Player player = playerController.getPlayer();

        SGCommonProto.PlayerBaseInfo.Builder baseInfo = SGCommonProto.PlayerBaseInfo.newBuilder();
        baseInfo.setPlayerIndex(player.getObjectIndex());
        baseInfo.setNickName(player.getName());
        baseInfo.setAvatar(player.avatar);
        baseInfo.setLv(player.getLv());
        baseInfo.setVipLv(player.getVipLevel());
        baseInfo.setExp(player.getExp());
        baseInfo.setFc(player.fc);
        baseInfo.setMasterId(player.master);
        baseInfo.setCamptypeValue(player.camp);
        baseInfo.setMobile(player.getMobile());
        int rTime = (int) (player.getCreateTime().getTime() / 1000);
        baseInfo.setRegistTime(rTime);

        SettingInfo settingInfo = player.getExtInfo(SettingInfo.class);
        int upLvTime = (int) (settingInfo.getLastLvUpTime() / 1000);
        baseInfo.setLastUpLvTime(upLvTime);
        data.addAllMasterTrainAttributes(settingInfo.getResponseMasterAttributes());
        data.addAllUseLiquidCount(settingInfo.getUseLiquidProp());
        data.addAllAds(getAdList(player));
        data.setBaseInfo(baseInfo);

        data.addAllCardGroups(getCardGroupProto(player, false));
        BagInfo bagInfo = player.getExtInfo(BagInfo.class);
        List<PropDB> propList = bagInfo.getPropList();
        SGCommonProto.BagProp.Builder propInfo = null;
        for (PropDB prop : propList) {
            propInfo = SGCommonProto.BagProp.newBuilder();
            propInfo.setId(prop.id);
            propInfo.setCount(prop.count);
            data.addProps(propInfo);
        }

        List<TimePropDB> timePropDBs = bagInfo.getTimePropData().getTimePropList();
        SGCommonProto.BagTimeProp.Builder bagTimeProp = null;
        for (TimePropDB db : timePropDBs) {
            bagTimeProp = SGCommonProto.BagTimeProp.newBuilder();
            bagTimeProp.setId(db.id);
            bagTimeProp.setUniqueId(db.uniqueId);
            bagTimeProp.setIsUse(db.isUse);
            bagTimeProp.setEndTime(db.endTime);
            data.addTimeProps(bagTimeProp);
        }

        Map<Integer, Integer> assetMap = bagInfo.getAssetData();
        SGCommonProto.FlushData.Builder assetData = null;
        for (Map.Entry<Integer, Integer> entry : bagInfo.getAssetData().entrySet()) {
            assetData = SGCommonProto.FlushData.newBuilder();
            assetData.setType(SGCommonProto.E_GOODS_TYPE.GOODS_TYPE_ASSETS);
            assetData.setId(entry.getKey());
            assetData.setChange(0);
            assetData.setCurValue(entry.getValue());

            data.addData(assetData);
        }

        TaskInfo taskInfo = player.getExtInfo(TaskInfo.class);
        Map<Integer, TaskDB> underwayMainTaskMap = taskInfo.underwayMainTaskMap;
        SGCommonProto.TaskDetail.Builder taskDetail = null;
        for (Map.Entry<Integer, TaskDB> entry : underwayMainTaskMap.entrySet()) {
            taskDetail = SGCommonProto.TaskDetail.newBuilder();
            TaskDB taskDB = entry.getValue();
            taskDetail.setTaskId(taskDB.id);
            taskDetail.setCurrentDemand(taskDB.currentDemand);
            taskDetail.setStatus(SGCommonProto.E_TASK_STATUS.forNumber(taskDB.status));
            data.setTaskDetail(taskDetail);
            break;
        }

        // 设置装备的技能和消费钻石不提醒的key
        data.addAllEquippedSkillIds(settingInfo.getEquipSkillIds());
        data.addAllConsumeNotRemindKeys(settingInfo.getConsumeNotRemindList());

        // 首冲情况
        RechargeRecordData recordData = playerController.getPlayer().getRechargeRecordData();
        data.setIsFirstRechargeComplete(recordData.isFirstRechargeComplete());
        if (recordData.isFirstRechargeComplete()) {
            BonusData bonusData = playerController.getPlayer().getBonusData();
            data.setIsFirstRechargeGiftReward(bonusData.isFistRechargeReceive());
        }
        // 引导的进度
        data.setGuideProgress(settingInfo.getGuideProgress());
        // 累计登录奖励是否显示
        boolean isShow = DataFactory.getInstance().getDataList(DataFactory.LOGIN_TIMES_REWARD_KEY).size() != player
                .getBonusData().getLoginRewardRecord().size();
        data.setIsLoginBonusShow(isShow);

        //是否有累计在线奖励
        OnlineRewardData onlineRewardData = playerController.getPlayer().getOnlineData();
        data.setHaveOnLineReward(onlineRewardData.isGetAllReward());
        // 黑名单
        data.addAllBlackPlayerList(settingInfo.getBlackList());
        // 大地图任务信息
        SGCommonProto.WorldMapTaskBaseInfo.Builder mapTaskBaseInfo = SGCommonProto.WorldMapTaskBaseInfo.newBuilder();
        WorldMapTaskData mapTaskInfo = player.getWorldMapTaskData();
        mapTaskBaseInfo.setGroupId(mapTaskInfo.getGroupId());
        mapTaskBaseInfo.setMilitaryExploitValue(mapTaskInfo.getMilitaryExploitValue());
        for (Map.Entry<Integer, WorldMapTaskBean> entry : mapTaskInfo.getWorldMapTaskValues().entrySet()) {
            SGCommonProto.WorldMapTaskObject.Builder worldMapTaskObject = SGCommonProto.WorldMapTaskObject.newBuilder();
            worldMapTaskObject.setType(SGCommonProto.E_WORLDMAPTASK_TYPE.forNumber(entry.getKey()));
            worldMapTaskObject.setValue(entry.getValue().getComplete());
            mapTaskBaseInfo.addWorldMapTaskValues(worldMapTaskObject);
        }
        data.setWorldMapTaskBaseInfo(mapTaskBaseInfo);
        data.setServerId(GameServer.getInstance().getServerId());
        //当前普通模式通关最大关卡
        data.setCurrentLevelId(player.getInstanceData().getMaxInstance(1));
        response.setUserBaseData(data);

        // LogUtils.debug("baseData:" + response);
        playerController.sendMsg(SGMainProto.E_MSG_ID.MsgID_Player_SynBaseData_VALUE, response.build().toByteArray());
    }

    private List<SGCommonProto.CardGroup> getCardGroupProto(Player player, boolean justBattle) {
        List<SGCommonProto.CardGroup> list = new ArrayList<>();
        BagInfo bagInfo = player.getBagInfo();
        CardData cardData = bagInfo.getCardData();
        SGCommonProto.CardGroup.Builder cardGroup = null;
        SGCommonProto.Card.Builder cardInfo = null;
        SGCommonProto.Accessory.Builder accessory = null;
        SGCommonProto.Equip.Builder equip = null;
        int groupId = 0;
        cardGroup = SGCommonProto.CardGroup.newBuilder();
        cardGroup.setGroupId(++groupId);
        cardGroup.setCardGroupType(SGCommonProto.E_CARDGROUP_TYPE.CARDGROUP_TYPE_BATTLE);
        for (CardDB cardDB : cardData.getBattleCardList()) {
            cardInfo = SGCommonProto.Card.newBuilder();
            cardInfo.setId(cardDB.id);
            cardInfo.setLv(cardDB.getLv());
            cardInfo.setStar(cardDB.star);
            cardInfo.setCurExp(cardDB.getExp());
            cardInfo.setFc(cardDB.fc);
            // 饰品
            for (Map.Entry<Integer, AccessoryDB> entry : cardDB.getAccessoryMap().entrySet()) {
                accessory = SGCommonProto.Accessory.newBuilder();
                accessory.setId(entry.getValue().id);
                accessory.setIntensifyLv(entry.getValue().getLv());
                accessory.setCurrentExp(entry.getValue().getExp());
                accessory.setIsActivated(entry.getValue().isActivated);
                accessory.setUpLv(entry.getValue().upLv);
                cardInfo.addAccessory(accessory);
            }
            // 装备
            for (Map.Entry<Integer, EquipDB> entry : cardDB.getEquipMap().entrySet()) {
                equip = SGCommonProto.Equip.newBuilder();
                equip.setId(entry.getValue().id);
                equip.setLv(entry.getValue().getLv());
                cardInfo.addEquip(equip);
            }
            // 宿命列表
            cardInfo.addAllActiveFateList(cardDB.getActiveFateList());
            // 吃药
            cardInfo.addAllUseLiquidCount(cardDB.getUseLiquidProp());
            cardGroup.addCards(cardInfo);
        }

        list.add(cardGroup.build());

        if (!justBattle) {
            cardGroup = SGCommonProto.CardGroup.newBuilder();
            cardGroup.setGroupId(++groupId);
            cardGroup.setCardGroupType(SGCommonProto.E_CARDGROUP_TYPE.CARDGROUP_TYPE_SLEEP);
            for (CardDB cardDB : cardData.getSleepCardList()) {
                cardInfo = SGCommonProto.Card.newBuilder();
                cardInfo.setId(cardDB.id);
                cardInfo.setLv(cardDB.getLv());
                cardInfo.setStar(cardDB.star);
                cardInfo.setCurExp(cardDB.getExp());
                cardInfo.setFc(cardDB.fc);

                // 饰品
                for (Map.Entry<Integer, AccessoryDB> entry : cardDB.getAccessoryMap().entrySet()) {
                    accessory = SGCommonProto.Accessory.newBuilder();
                    accessory.setId(entry.getValue().id);
                    accessory.setIntensifyLv(entry.getValue().getLv());
                    accessory.setCurrentExp(entry.getValue().getExp());
                    accessory.setIsActivated(entry.getValue().isActivated);
                    accessory.setUpLv(entry.getValue().upLv);
                    cardInfo.addAccessory(accessory);
                }
                // 装备
                for (Map.Entry<Integer, EquipDB> entry : cardDB.getEquipMap().entrySet()) {
                    equip = SGCommonProto.Equip.newBuilder();
                    equip.setId(entry.getValue().id);
                    equip.setLv(entry.getValue().getLv());
                    cardInfo.addEquip(equip);
                }
                // 宿命列表
                cardInfo.addAllActiveFateList(cardDB.getActiveFateList());
                // 吃药
                cardInfo.addAllUseLiquidCount(cardDB.getUseLiquidProp());
                cardGroup.addCards(cardInfo);
            }
            list.add(cardGroup.build());
        }
        return list;
    }

    public List<Integer> getAdList(Player player) {
        List<Integer> ids = new ArrayList<>();
        List<AdConfig> ads = DataFactory.getInstance().getDataList(DataFactory.AD_KEY);
        for (AdConfig config : ads) {
            if (player.getLv() < config.openCondition) {
                continue;
            }

            if (!config.isTimeIn()) {
                continue;
            }

            if (config.id == E_AdType.FIRST_RECHARGE.getCode()) {
                if (!player.getRechargeData().isFirstRechargeComplete()) {
                    ids.add(config.id);
                }
            } else if (config.id == E_AdType.TOTAL_LOGIN.getCode()) {
                if (player.getBonusData().getLoginTimesByDay() < 7) {
                    ids.add(config.id);
                }
            } else if (config.id == E_AdType.RECHARGE_STRATEGY.getCode()) {
                if (RechargeGuideUtils.isRechargeGuideShow(player)) {
                    ids.add(config.id);
                }
            } else {
                continue;
            }

        }

        return ids;
    }

    /**
     * 主将培养
     *
     * @param playerController
     * @param data
     * @param code
     */
    private void masterTrain(PlayerController playerController, byte[] data, int code) {
        SGPlayerProto.C2S_MasterTrain request = null;
        try {
            request = SGPlayerProto.C2S_MasterTrain.parseFrom(data);
        } catch (InvalidProtocolBufferException e) {
            e.printStackTrace();
        }
        if (request == null) {
            playerController.sendWarn(WordFactory.PARAM_ERROR);
            return;
        }

        SGCommonProto.E_MASTER_TRAIN_TYPE trainType = request.getTrainType();
        SettingInfo settingInfo = playerController.getPlayer().getExtInfo(SettingInfo.class);
        if (trainType != SGCommonProto.E_MASTER_TRAIN_TYPE.MASTER_TRAIN_TYPE_UNKNOW) {
            StableDataConfig config;
            if (trainType == SGCommonProto.E_MASTER_TRAIN_TYPE.MASTER_TRAIN_TYPE_NORMAL) {
                config = DataFactory.getInstance().getGameObject(DataFactory.STABLE_DATA_KEY,
                        E_StableDataType.MASTER_TRAIN_NORMAL.getCode());
            } else if (trainType == SGCommonProto.E_MASTER_TRAIN_TYPE.MASTER_TRAIN_TYPE_SENIOR) {
                config = DataFactory.getInstance().getGameObject(DataFactory.STABLE_DATA_KEY,
                        E_StableDataType.MASTER_TRAIN_SENIOR.getCode());
            } else {
                playerController.sendWarn(WordFactory.PARAM_ERROR);
                return;
            }
            BagInfo bagInfo = playerController.getPlayer().getExtInfo(BagInfo.class);
            for (GoodsData goods : config.goods) {
                if (bagInfo.getGoodsCount(goods.type, goods.id) < goods.value) {
                    // 钻石资源不足
                    LogUtils.debug("培养物品不足：" + goods.value);
                    if (goods.type == SGCommonProto.E_GOODS_TYPE.GOODS_TYPE_ASSETS_VALUE) {
                        playerController.sendWarn(WordFactory.ASSET_NOT_ENOUGH, goods.id);
                    } else {
                        playerController.sendWarn(WordFactory.GOODS_NOT_ENOUGH, goods.id);
                    }
                    return;
                }
            }
            // 扣除资源
            bagInfo.addGoods(new GoodsData[]{}, config.goods);
            DataFactory.getInstance().getMasterTrainChangeValue(5, trainType,
                    settingInfo.getMasterLastChangeAttributes());

            // 任务检测
            if (trainType == SGCommonProto.E_MASTER_TRAIN_TYPE.MASTER_TRAIN_TYPE_SENIOR) {
                // 检测任务是否完成
                playerController.getPlayer().getExtInfo(TaskInfo.class)
                        .check(TaskFactory.TASK_TARAGET_EVERYDAY_PROPERTIE_STONE, 1);
            }
            playerController.getPlayer().getExtInfo(TaskInfo.class).check(TaskFactory.TASK_TARAGET_EVERYDAY_PROPERTIE, 1);
        }
        List<SGCommonProto.CommonObject> changeAttributes = settingInfo.getResponseMasterLastChangeAttributes();
        playerController.sendMsg(code,
                SGPlayerProto.S2C_MasterTrain.newBuilder().addAllChangeValue(changeAttributes).build().toByteArray());
    }

    /**
     * 主将培养接受
     *
     * @param playerController
     * @param data
     * @param code
     */
    private void masterTrainAccept(PlayerController playerController, byte[] data, int code) {
        SettingInfo settingInfo = playerController.getPlayer().getExtInfo(SettingInfo.class);
        int max;
        int temp;
        MasterTrainConfig config;
        Map<Integer, Integer> masterAttributes = settingInfo.getMasterAttributes();
        for (Map.Entry<Integer, Integer> entry : settingInfo.getMasterLastChangeAttributes().entrySet()) {
            config = DataFactory.getInstance().getGameObject(DataFactory.MASTER_TRAIN_KEY, entry.getKey());
            max = config.maxLevel[Math.min(config.maxLevel.length - 1, playerController.getPlayer().getLv() - 1)];
            if (masterAttributes.get(entry.getKey()) != null) {
                temp = masterAttributes.get(entry.getKey()) + entry.getValue();
                temp = Math.max(temp, 0);
                temp = Math.min(temp, max);
                masterAttributes.put(entry.getKey(), temp);
            } else {
                masterAttributes.put(entry.getKey(), entry.getValue());
            }
        }

        settingInfo.getMasterLastChangeAttributes().clear();

        playerController.updateFC();
        List<SGCommonProto.CommonObject> responseMasterAttributes = settingInfo.getResponseMasterAttributes();
        LogUtils.debug("本次培养接受的最终值：" + responseMasterAttributes);
        playerController.sendMsg(code, SGPlayerProto.S2C_MasterTrain.newBuilder()
                .addAllChangeValue(responseMasterAttributes).build().toByteArray());
        return;
    }

    /**
     * 设置自动使用药水
     *
     * @param playerController
     * @param data
     * @param code
     */
    private void settingAutoRecover(PlayerController playerController, byte[] data, int code) {
        SGPlayerProto.C2S_SetAutoRecover request = null;
        try {
            request = SGPlayerProto.C2S_SetAutoRecover.parseFrom(data);
        } catch (InvalidProtocolBufferException e) {
            e.printStackTrace();
        }
        SGCommonProto.AutoRecoverInfo autoRecoverInfo = request.getRecoverInfo();
        if (autoRecoverInfo.getUseTimes() > 99 || autoRecoverInfo.getUseTimes() < 1) {
            LogUtils.error(
                    "玩家" + playerController.getObjectIndex() + "设置自动使用药水使用次数参数异常： -> " + autoRecoverInfo.getUseTimes());
            playerController.sendWarn(WordFactory.PARAM_ERROR);
            return;
        }

        if (autoRecoverInfo.getPercent() > 99 || autoRecoverInfo.getPercent() < 1) {
            LogUtils.error(
                    "玩家" + playerController.getObjectIndex() + "设置自动使用药水百分比参数异常： -> " + autoRecoverInfo.getPercent());
            playerController.sendWarn(WordFactory.PARAM_ERROR);
            return;
        }

        LogUtils.debug("----设置自动回雪-------" + autoRecoverInfo);

        // 设置
        SettingInfo settingInfo = playerController.getPlayer().getExtInfo(SettingInfo.class);
        settingInfo.getAutoRecover().enable = autoRecoverInfo.getEnable();
        settingInfo.getAutoRecover().maxUseTimes = autoRecoverInfo.getUseTimes();
        settingInfo.getAutoRecover().percent = autoRecoverInfo.getPercent();

        SGPlayerProto.S2C_SetAutoRecover.Builder response = SGPlayerProto.S2C_SetAutoRecover.newBuilder();
        SGCommonProto.AutoRecoverInfo.Builder builder = SGCommonProto.AutoRecoverInfo.newBuilder();
        builder.setEnable(autoRecoverInfo.getEnable());
        builder.setUseTimes(autoRecoverInfo.getUseTimes());
        builder.setPercent(autoRecoverInfo.getPercent());
        response.setRecoverInfo(builder);
        playerController.sendMsg(code, response.build().toByteArray());
    }

    private void buyFlashSale(PlayerController playerController, byte[] data, int code) {
        SGPlayerProto.C2S_BuyFlashSale request = null;
        try {
            request = SGPlayerProto.C2S_BuyFlashSale.parseFrom(data);
        } catch (InvalidProtocolBufferException e) {
            e.printStackTrace();
        }

        playerController.getPlayer().getBonusData().consumeItemFishFlashSale(playerController,request.getId());

        SGPlayerProto.S2C_BuyFlashSale.Builder response = SGPlayerProto.S2C_BuyFlashSale.newBuilder();
        playerController.sendMsg(code, response.build().toByteArray());
    }

    private boolean isOpenActivityHall(PlayerController playerController){
        String message = CoreUtils.checkFunctionOpen(FunctionFactory.ACTIVITY_HALL,playerController.getPlayer());
        if (!CoreUtils.isNullOrEmpty(message)){
            LogUtils.error("等级不够，系统未开放");
            playerController.sendWarn(WordFactory.FUNCTION_NOT_OPEN,message);
            return false;
        }
        return true;
    }

    /**
     * 初始化活动大厅日类型
     * @param playerController
     * @param data
     * @param code
     */
    private void initActivityHallDay(PlayerController playerController,byte[] data,int code){
        //验证活动是否开放
        if (!isOpenActivityHall(playerController))
            return;
        //验证收到的参数是否正确
        SGPlayerProto.C2S_InitActivityHallDay request = null;
        try {
            request = SGPlayerProto.C2S_InitActivityHallDay.parseFrom(data);
        } catch (InvalidProtocolBufferException e) {
            e.printStackTrace();
        }
        if (request.getType() != ACTIVITY_HALL_TYPE_MAIN){
            LogUtils.error("参数错误 ，不认识的类型");
            playerController.sendWarn(WordFactory.PARAM_ERROR);
            return;
        }

        SGPlayerProto.S2C_InitActivityHallDay.Builder response = SGPlayerProto.S2C_InitActivityHallDay.newBuilder();

        GameServer.getInstance().getActivityDayInfoList(playerController.getPlayer()).forEach((i)->{
            response.addActivityList(i);
        });
        response.setCurrentTime(DataFactory.currentTime);
        playerController.sendMsg(code,response.build().toByteArray());
        LogUtils.debug("返回活动大厅 日历初始化成功 ");
    }

    /**
     * 初始化活动大厅周历
     * @param playerController
     * @param code
     */
    private void initActivityHallWeek(PlayerController playerController,int code){
        if (!isOpenActivityHall(playerController))
            return;
        SGPlayerProto.S2C_InitActivityHallWeek.Builder response = SGPlayerProto.S2C_InitActivityHallWeek.newBuilder();
        GameServer.getInstance().getActivityWeekInfoList().forEach((i)->{
            response.addColumnList(i);
        });
        response.setEndTime(CoreUtils.getInWeekTime().getSecond());
        playerController.sendMsg(code,response.build().toByteArray());
        LogUtils.debug("返回活动大厅 周历初始化成功 ");
    }
}
